﻿namespace RestaurantMenu.Library
{
    using System;

    public struct NutritionFacts
    {
        // fields
        private int calories;
        private int proteins;
        private int carbohydrates;
        private int fat;

        // constructors
        public NutritionFacts(int calories, int proteins, int carbohydrates, int fat)
            : this()
        {
            this.Calories = calories;
            this.Proteins = proteins;
            this.Carbohydrates = carbohydrates;
            this.Fat = fat;
        }

        // properties
        public int Calories
        {
            get
            {
                return this.calories;
            }

            private set
            {
                if (value < 0)
                {
                    throw new ArgumentException("The calories can not have negative number!");
                }

                this.calories = value;
            }
        }

        public int Proteins
        {
            get
            {
                return this.proteins;
            }

            private set
            {
                if (value < 0)
                {
                    throw new ArgumentException("The proteins can not have negative number!");
                }

                this.proteins = value;
            }
        }

        public int Carbohydrates
        {
            get
            {
                return this.carbohydrates;
            }

            private set
            {
                if (value < 0)
                {
                    throw new ArgumentException("The nutrients can not have negative number!");
                }

                this.carbohydrates = value;
            }
        }

        public int Fat
        {
            get
            {
                return this.fat;
            }

            private set
            {
                if (value < 0)
                {
                    throw new ArgumentException("The fat can not have negative number!");
                }

                this.fat = value;
            }
        }

        // methods
        public override string ToString()
        {
            return string.Format("Calories : {0} kJ , Proteins : {1} g, Carbohydrates : {2} g, Fat : {3} g", this.Calories, this.Proteins, this.Carbohydrates, this.Fat);
        }

        public static NutritionFacts operator +(NutritionFacts first, NutritionFacts second)
        {
            return new NutritionFacts(first.Calories + second.Calories, first.Proteins + second.Proteins, first.Carbohydrates + second.Carbohydrates, first.Fat + second.Fat);
        }
    }
}